package com.ymatou.iapi.thirdpartysync.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.thirdpartysync.parameter.GetProductLinkBean;
import com.ymatou.iapi.thirdpartysync.service.GetProductLinkCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.utils.EnvSetup;
/**
*获取短连接Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductLink{
	private static GetProductLinkBean getproductlinkBean;
	private static GetProductLinkCall getproductlinkCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取短连接Test");
	}

	@Before
	public void caseUp() {
		getproductlinkBean=new GetProductLinkBean();
		getproductlinkCall=new GetProductLinkCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductlinkCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductLink_001() {
		Logger.start(true,"正确数据，成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(3000);
			//添加推广商品
			ThirdpartysyncCallService.insertPromotionProduct(productId, sellerId, 0.03);
			
			getproductlinkBean.setApp_key("appidtest");
			getproductlinkBean.setDetail_url("https://www.ymatou.com/product/"+productId+".html");
			getproductlinkBean.setPid("pidtest");
			getproductlinkBean.setSign("ymtymt");
			getproductlinkBean.setStat_param("ssss3");
			getproductlinkCall.setData(getproductlinkBean);
			getproductlinkCall.callService();			
			Logger.verifyEquals("200", getproductlinkCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}